﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace HeUtils
{
    public static class Sha256Util
    {
        public static byte[] FileChecksumByte(string filePath)
        {
            using (FileStream fs = File.OpenRead(filePath))
            {
                SHA256 sha256 = SHA256.Create();
                return sha256.ComputeHash(fs);
            }
        }

        public static string FileChecksumString(string filePath)
        {
            byte[] checksum = FileChecksumByte(filePath);
            return BitConverter.ToString(checksum).Replace("-", "");
        }

        public static byte[] ChecksumByte(byte[] data)
        {
            SHA256 sha256 = SHA256.Create();
            return sha256.ComputeHash(data);
        }

        public static string ChecksumString(byte[] data)
        {
            byte[] checksum = ChecksumByte(data);
            return BitConverter.ToString(checksum).Replace("-", "");
        }

        public static string ChecksumBase64(byte[] data)
        {
            byte[] checksum = ChecksumByte(data);
            return Convert.ToBase64String(checksum);
        }
    }
}
